/*
 * File:   util_conv.c
 * Author: Ich
 *
 * Created on 12. Januar 2014, 16:59
 *
 * Description:
 * -
 */

#include <plib.h>
/*******************************************************************************
 *  private preprocessing definitions
 */

/*******************************************************************************
 *  private variables
 */

/*******************************************************************************
 *  private functions
 */

/*******************************************************************************
 *  public variables (defined by external)
 */

/*******************************************************************************
 *  public functions
 */

BOOL utilConv_bcd2dec(UINT8 inBCD, UINT8 *outDec)
{
    BOOL successful = FALSE;

    // check range
    if( ((inBCD & 0x0F) < 0x0A) &&
        ((inBCD & 0xF0) < 0xA0) )
    {
        // BCD-Value inside range
        *outDec =   (inBCD & 0x0F) +
                    ((inBCD & 0xF0)>>4)*10;
    }

    return successful;
}


BOOL utilConv_dec2bcd(UINT8 inDec, UINT8 *outBcd)
{
    BOOL successful = FALSE;

    // check range
    if( inDec < 100 )
    {
        // BCD-Value inside range
        *outBcd =   (inDec % 10) +
                    ((inDec /10)<<4);
    }

    return successful;
}
